package com.cn.juc.ex.demo;

import org.junit.jupiter.api.Test;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: zhangyi
 * @date: 2019/1/12 14:20
 * @description:
 */
public class Fool {
    AtomicInteger id = new AtomicInteger(0);

    class Fool1 extends Thread{

        public Fool1(String name) {
            super(name);
        }

        @Override
        public void run() {
            System.out.print(this.getName()+" ");
            Thread.yield();
        }

        @Override
        public long getId() {
            return id.getAndIncrement();
        }
    }


    class Fool2 extends Thread{

        public Fool2(String name) {
            super(name);
        }

        @Override
        public void run() {
            System.out.print(this.getName()+" ");
            Thread.yield();
        }

        @Override
        public long getId() {
            return id.getAndIncrement();
        }
    }

    class Fool3 extends Thread{

        public Fool3(String name) {
            super(name);
        }

        @Override
        public void run() {
            System.out.print(this.getName()+" "+" ");
            Thread.yield();
        }

        @Override
        public long getId() {
            return id.getAndIncrement();
        }
    }

    @Test
    public void thread() {
        for (int i = 0; i < 10; i++){
            Fool1 fool1 = new Fool1("1");
            Fool2 fool2 = new Fool2("2");
            Fool3 fool3 = new Fool3("3");
            fool1.start();
            fool2.start();
            fool3.start();
        }
    }
}
